#include <iostream>
#include <algorithm>
using namespace std;

const int N = 3e5 + 10;

int n, k;
int arr[N];

void print()
{
	for (int i = 1; i <= n; i++)
		cout << arr[i] << " ";
	cout << endl;
}

int main()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	sort(arr + 1, arr + n + 1);
	// print();

	int sum = 0, j = 1; // 恢复之力
	while (k--)
	{
		int x = arr[j];
		while (x)
		{
			if (x == 1)
			{
				sum += 1;
				x--;
				j++;
			}
			else
			{
				sum += x;
				x -= 1;
				break;
			}
		}
	}

	cout << sum << endl;

	return 0;
}